package com.ihr360.excel.dao;

import com.ihr360.excel.model.dto.SpreadSheet;
import com.ihr360.excel.model.type.SpreadSheetStatus;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface SpreadSheetRepository extends JpaRepository<SpreadSheet, String> {

    @Modifying
    @Query(" update SpreadSheet set status = :finishedStatus where progressKey = :progressKey and status != :finishedStatus")
    void fineshedHistory(@Param("progressKey") String progressKey,@Param("finishedStatus") SpreadSheetStatus finishedStatus);

    SpreadSheet findByProgressKeyAndStatus(String progressKey, SpreadSheetStatus inprogress);

    @Query(value = " select * from SpreadSheet s where progressKey = :progressKey order by createdAt desc limit 1 ",nativeQuery = true)
    SpreadSheet findLastFinishSpreSheet(@Param("progressKey") String progressKey);
}
